package wyh.controller.Escort;

import com.fasterxml.jackson.databind.ObjectMapper;
import wyh.pojo.Escort;
import wyh.pojo.Patient;
import wyh.pojo.User;
import wyh.service.EscortService;
import wyh.service.PatientService;
import wyh.service.UserService;
import wyh.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//9666666666666666666 ok
@WebServlet("/Escort/GetEscortByUserId")
public class GetEscortByUserIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int UserId = Integer.parseInt(req.getParameter("UserId"));
        System.out.println("访问/Escort/GetEscortByUserId?UserId=" + UserId + ".");
        UserService service = new UserService();
        User pojo = service.ServicegetById(UserId);
        Result result;
        if (null == pojo) {
             result = new Result(200, "查询失败", null);
        } else {
            EscortService service0 = new EscortService();
            Escort pojoUser = service0.ServicegetById(pojo.getEscort_id());

             result = new Result(200, "查询成功", pojoUser);

            System.out.println("返回结果：" + pojoUser + "。");
        }
        ObjectMapper ojmapper = new ObjectMapper();
        String json = ojmapper.writeValueAsString(result);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);
    }
}
